\section{cumsum --- Cumulative Summation}
\label{fn:cumsum}
\index{cumsum()}
\index{cumulative summation}
\begin{rail}
CumSum : 'cumsum' '(' Matrix ')' ;
\end{rail}

\verb+cumsum+ takes a matrix argument, and produces another matrix
of the same dimensions. Each element in the resultant matrix consists 
of the cumulative sum of the that element and all previous elements
in that column  of the argument matrix. If the argument is either a row
or column vector, the cumulative summation is performed on that row or
column.

$\Longrightarrow$ This is not an \RLaB\ built-in function.  This function
is normally loaded on start-up from the \verb+cumsum.r+ file in the
standard \verb+rlib+ directory. Use of the \verb+-r+ option, incorrectly 
setting the \verb+RLAB_LIB_DIR+ environmental variable, or modifying
\verb+cumsum.r+ may make this function unavailable.


\paragraph{Example}
\index{example of cumsum()}
\index{cumsum()!example}
\begin{verbatim}
> cumsum([1,2,3,4,5])
        1          3          6         10         15  
> cumsum([1,2,3,4]')
        1  
        3  
        6  
       10  
> c = [1,2,3; 4,5,6; 7,8,9; 10, -3.4, 2.09]
 c =
        1          2          3  
        4          5          6  
        7          8          9  
       10       -3.4       2.09  
> cumsum(c)
        1          2          3  
        5          7          9  
       12         15         18  
       22       11.6       20.1
\end{verbatim}

See also: Page~\pageref{fn:cumprod} \verb+cumprod()+.

\newpage






